package com.foreknow.demo25;

import java.io.*;

/**
 * DataInputStream 数据输入流
 * DataOutputStream 数据输出流
 */
public class DataStreamDemo {
  public static void main(String[] args) {
    FileOutputStream fos = null;
    DataOutputStream dos = null;
    try {
//      fos = new FileOutputStream("new_file.ser");
//      dos = new DataOutputStream(fos);
//      dos.writeUTF("向文件中写入一个UTF-8编码模式的字符串（与平台无关的）");
//      dos.writeInt(40);
//      dos.close();

      //读取new_file.ser文件
      FileInputStream fis = new FileInputStream("new_file.ser");
      DataInputStream dis = new DataInputStream(fis);
      System.out.println("读取到的字符串为:"+dis.readUTF());
      System.out.println("年龄:"+dis.readInt());
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
}
